<?php
namespace App\Http\Controllers\Partner;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\PartnerModels\Partner;
use App\Models\AdminModels\Industry;
use App\Models\AdminModels\Config;
use App\Models\OrderModels\Order;
use App\Models\PartnerModels\Keyword;

class VipController extends Controller{
	
	//会员列表页面
    public function index(){
        return view('partner/vip/index',['admin_vip_menu'=>true]);
    }
	//会员添加页面
	public function create(){
		$path='/config/inquiry.json';
		$inquiry=\App\Components\Tools::getThird($path);
		
		$vip_discount=\App\Components\Tools::getOneconfig('/config/config.json',array('basics','vip_discount'));

		$oIndustry = new Industry();
		$industries = $oIndustry->getAllData();
		
		$partner=new Partner();
		$pList=$partner->selectPartner();
		
		return view('partner/vip/create',['admin_vip_menu'=>true,'industries'=>$industries,'vip_discount'=>$vip_discount,'inquiry'=>$inquiry,'pList'=>$pList]);
	}
	
	//会员修改页面
	public function edit($id){
		$path='/config/inquiry.json';
		$inquiry=\App\Components\Tools::getThird($path);
		
		$vip_discount=\App\Components\Tools::getOneconfig('/config/config.json',array('basics','vip_discount'));
		if(intval($id) > 0){
			$orderinfo=new Order();
			$orderlist=$orderinfo->selectOne(array('partner_id'=>$id,'type'=>3));
			
			$oPartner = new Partner();
			$data = $oPartner->db_get(['id'=>['=',$id]]);
			if(!empty($data)){
				$oIndustry = new Industry();
				$industries = $oIndustry->getAllData();
			}
			
			$partner=new Partner();
			$pList=$partner->selectPartner();
			
			$meal=$partner->selectMealName($id);
			
			return view('partner/vip/edit',['admin_vip_menu'=>true,'data'=>$data,'industries'=>$industries,'orderlist'=>$orderlist,'vip_discount'=>$vip_discount,'inquiry'=>$inquiry,'pList'=>$pList,'meal'=>$meal]);
		}
		abort(404);
	}

	//会员详情页面
	public function view($id){
		$oPartner = new Partner();
		$config=Config('basics.pay_type');
		if(intval($id) > 0){
			
			$values=array(
				'a.id'=>$id,
				'a.type'=>2,
				'b.type'=>3
			);
			$data=$oPartner->listOne($values,1);
			if($data){
				// echo "<pre/>";print_r($data);exit;
				$data['pay_type_name']=$config[$data['pay_type']];
				if($data['gender']==1){
					$data['gender']="男";
				}elseif($data['gender']==2){
					$data['gender']="女";
				}else{
					$data['gender']="未知";
				}
				if($data['status']==1){
					$data['status']="开启";
				}elseif($data['status']==0){
					$data['status']="关闭";
				}else{
					$data['status']="已删除";
				}
			}
			return view('partner/vip/view',['admin_vip_menu'=>true,'data'=>$data]);
		}
		abort(404);
	}
    //关键词详情
    public function keyword($id){
        $oPartner = new Partner();
        $config=Config('basics.pay_type');
            $data=$oPartner->getname($id);
      //   print_r($data);exit();
            return view('partner/vip/keyword',['admin_vip_menu'=>true,'data'=>$data]);

    }
}